<% var jstpl={ %>
    <script src="${basepath}/plugin/qn_jssdk/plupload/plupload.full.min.js"></script>
    <script src="${basepath}/plugin/qn_jssdk/qiniu.dev.js"></script>
    <script>
        var form = layui.form;
        form.on('submit(form_submit)', function(data) {
            Ajax("/system/banner/save", data.field, function(ret) {
                if (ret.state) {
                    location.href = "/system/banner";
                } else {
                    layer.msg(ret.msg);
                }
            });
            // console.log(data.elem); //被执行事件的元素DOM对象，一般为button对象
            // console.log(data.form); //被执行提交的form对象，一般在存在form标签时才会返回
            // console.log(data.field); //当前容器的全部表单字段，名值对形式：{name: value}
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        imgupload({
            elm: "#logo_upload", // 标签，类名或 ID 不能重复
            thumb_w: 150, // 返回缩略图的宽度
            thumb_h: 95, // 返回缩略图的高度
            fsize: 1.5, // 图片大小限制（MB），默认 100MB
            rery: 3, // 上传失败重试次数，默认 1
            multi: false, // 上传多张
            UploadProgress: function(up, file) {}, // up：对象实例，file：文件上传信息
            FileUploaded: function(img, thumb) {
                    $("#logo").attr("src", thumb);
                    $("input[name='banner.img']").val(img);
                } // img：图片原图，thumb：缩略图
        });
    </script>
    <% }; %>
        <%layout("../layout/_layout_layui.html",{title:"添加/编辑轮播图",jstpl:jstpl}){ %>
            <form class="layui-form">
                <input type="hidden" name="banner.id" value="${banner.id!}">
                <div class="layui-form-item">
                    <label class="layui-form-label">标题</label>
                    <div class="layui-input-block">
                        <input type="text" name="banner.title" value="${banner.title!}" lay-verify="required" autocomplete="off" placeholder="请输入标题" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">图片</label>
                    <div class="layui-input-block">
                        <div class="layui-upload">
                            <div class="layui-upload-list">
                                <% if((banner.img!null)==null){ %>
                                    <img style="width: 150px;height: 95px;" id="logo">
                                    <% }else{ %>
                                        <img style="width: 150px;height: 95px;" src="${banner.img!}?imageView2/1/w/150/h/95" id="logo">
                                        <% } %>
                                            <p id="demoText">图片推荐尺寸：690X270</p>
                            </div>
                            <input type="hidden" lay-verify="required" name="banner.img" value="${banner.img!}">
                            <button type="button" class="layui-btn" id="logo_upload">上传图片</button>
                        </div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">排序</label>
                    <div class="layui-input-block">
                        <input type="number" name="banner.sort" value="${banner.sort!}" lay-verify="required,number" autocomplete="off" placeholder="请输入排序" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">状态</label>
                    <div class="layui-input-block">
                        <input type="checkbox" ${(banner.state!1)==1? "checked": ""} name="banner.state" value="1" lay-skin="switch" lay-text="ON|OFF">
                    </div>
                </div>
                <div class="layui-form-item layui-layout-admin">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="form_submit">提交</button>
                        <!--<button type="reset" class="layui-btn layui-btn-primary">重置</button>-->
                    </div>
                </div>
            </form>
            <%}%>